/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.ticketdata.leadershipdata.service;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.jeeplus.common.utils.IdGen;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.peopleinformation.peopleassessaccount.entity.PeopleAssessAccount;
import com.jeeplus.modules.peopleinformation.peopleassessaccount.service.PeopleAssessAccountService;
import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.utils.UserUtils;
import com.jeeplus.modules.ticketdata.unitdata.entity.UnitData;
import com.jeeplus.modules.ticketdata.unitdata.service.UnitDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.ticketdata.leadershipdata.entity.LeadershipData;
import com.jeeplus.modules.ticketdata.leadershipdata.mapper.LeadershipDataMapper;

/**
 * 领导班子数据Service
 * @author 刘明星
 * @version 2021-10-29
 */
@Service
@Transactional(readOnly = true)
public class LeadershipDataService extends CrudService<LeadershipDataMapper, LeadershipData> {

	@Autowired
    private UnitDataService unitDataService;
	@Autowired
	private PeopleAssessAccountService peopleAssessAccountService;
	public LeadershipData get(String id) {
		return super.get(id);
	}
	
	public List<LeadershipData> findList(LeadershipData leadershipData) {
		return super.findList(leadershipData);
	}
	
	public Page<LeadershipData> findPage(Page<LeadershipData> page, LeadershipData leadershipData) {
		return super.findPage(page, leadershipData);
	}
	
	@Transactional(readOnly = false)
	public void save(LeadershipData leadershipData) {
		super.save(leadershipData);
	}
	@Transactional(readOnly = false)
	public void manysave(PeopleAssessAccount peopleAssessAccount, LeadershipData manysave, UnitData unitData) {
		/*
			循环插入数据
		 */
		if (peopleAssessAccount != null) {
			peopleAssessAccountService.updateFinishState(peopleAssessAccount);
		}
		if (manysave != null) {
			for (LeadershipData testDataChild21 : manysave.getMiddlerleader()){
				if (testDataChild21.getId() == null){
					testDataChild21.setId(IdGen.uuid());
					if (LeadershipData.DEL_FLAG_NORMAL.equals(testDataChild21.getDelFlag())){
						User user = UserUtils.getUser();
						testDataChild21.setUpdateBy(user);
						testDataChild21.setCreateBy(user);
						testDataChild21.setUpdateDate(new Date());
						testDataChild21.setCreateDate(new Date());
						mapper.insert(testDataChild21);
					}
				}
			}
		}
		if (unitData != null) {
			unitDataService.manysave(unitData);
		}
	}

	@Transactional(readOnly = false)
	public void delete(LeadershipData leadershipData) {
		super.delete(leadershipData);
	}
	
}